package com.chen.Dome3Annotation;

import org.junit.Test;

import java.lang.reflect.Method;
import java.util.Arrays;

public class AnnotationDome3 {
        //目标解析注解
    @Test
    public void parseClass(){
        //获取类对象
        Class clazz=Dome.class;
        //isAnnotationPresent判断这个类上面是否有注解
        if(clazz.isAnnotationPresent(MyTest2.class)){
            //获取注解对象
            MyTest2 myTest2= (MyTest2) clazz.getAnnotation(MyTest2.class);
            //获取注解的属性值
            System.out.println(myTest2.value());
            System.out.println(myTest2.aaa());
            System.out.println(Arrays.toString(myTest2.bbb()));
        }
    }
    @Test
    public void parseMethod() throws Exception{
        //获取类对象
        Class clazz=Dome.class;
        Method method=clazz.getMethod("go");
        //判断方法上面是否有注解
        if(method.isAnnotationPresent(MyTest2.class)){
            //获取注解对象
            MyTest2 myTest2= (MyTest2) method.getDeclaredAnnotation(MyTest2.class);
            //获取注解的属性值
            System.out.println(myTest2.value());
            System.out.println(myTest2.aaa());
            System.out.println(Arrays.toString(myTest2.bbb()));
        }
    }
}
